@extends('../manage.layout')
@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            授权管理
            <small>权限列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    {{--<div class="box-header with-border">--}}
                        {{--<h3 class="box-title"></h3>--}}
                    {{--</div>--}}
                    <!-- table start -->
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">信息</h3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="rule/create" class="btn btn-primary">添加授权</a>

                                    {{--<div class="box-tools">--}}
                                        {{--<div class="input-group input-group-sm" style="width: 150px;">--}}
                                            {{--<input type="text" name="table_search" class="form-control pull-right" placeholder="Search">--}}

                                            {{--<div class="input-group-btn">--}}
                                                {{--<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>--}}
                                            {{--</div>--}}
                                        {{--</div>--}}
                                    {{--</div>--}}
                                </div>
                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                        <tr>
                                            <th>ID</th>
                                            <th>创建时间</th>
                                            <th>更新时间</th>
                                            <th>权重</th>
                                            <th>角色名</th>
                                            <th>表名</th>
                                            <th>查看</th>
                                            <th>增加</th>
                                            <th>修改</th>
                                            <th>删除</th>
                                            {{--<th>状态</th>--}}
                                            <th>操作</th>
                                        </tr>
                                        @foreach($rule as $v)
                                            <tr>
                                                <td>{{ $v['id'] }}</td>
                                                <td>{{ $v['create_time'] }}</td>
                                                <td>{{ $v['update_time'] }}</td>
                                                <td>{{ $v['rank'] }}</td>
                                                <td>{{ App\Role::find($v['role_id'])['name'] }}</td>
                                                <td>{{ App\Table::find($v['table_id'])['name_zh'] }}</td>
                                                <td>
                                                    <a href="javascript:setRule('view','{{ $v['view'] }}','{{$v['id']}}')">
                                                        @if($v['view'] == 1)<span class="label label-success">是</span>
                                                        @else<span class="label label-warning">否</span>
                                                        @endif
                                                    </a>
                                                </td>
                                                <td>
                                                    <a href="javascript:setRule('add','{{ $v['add'] }}','{{$v['id']}}')">
                                                    @if($v['add'] == 1)<span class="label label-success">是</span>
                                                    @else<span class="label label-warning">否</span>
                                                    @endif
                                                    </a>
                                                </td>
                                                <td>
                                                    <a href="javascript:setRule('update','{{ $v['update'] }}','{{$v['id']}}')">
                                                    @if($v['update'] == 1)<span class="label label-success">是</span>
                                                    @else<span class="label label-warning">否</span>
                                                    @endif
                                                    </a>
                                                </td>
                                                <td>
                                                    <a href="javascript:setRule('delete','{{ $v['delete'] }}','{{$v['id']}}')">
                                                    @if($v['delete'] == 1)<span class="label label-success">是</span>
                                                    @else<span class="label label-warning">否</span>
                                                    @endif
                                                    </a>
                                                </td>
                                                <td>
                                                    {{--<a href="role/{{ $v['id'] }}/edit"><span class="label label-primary">更改</span></a>--}}
                                                    <a href="javascript:delSubscribe({{ $v['id'] }})"><span class="label label-danger">删除</span></a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </table>
                                </div>
                                <!-- /.box-body -->
                            </div>
                            <!-- /.box -->
                        </div>
                    </div>
                    <!-- /.table -->
                    <div style="text-align: center">{{ $rule->links() }}</div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
@endsection
<script>
    function delSubscribe(id) {
        layer.confirm('删除不可恢复，是否继续？', {
            btn:['确定','取消'] //按钮
        }, function() {
            $.ajax({
               url: '/manage/rule/destroy',
                type:'get',
                data:{id:id},
                async:false,
                dataType:'json',
                success:function(res){
                    if(res.code==100) {
                        layer.msg(res.msg, {time:1500, icon:6, end:function(){location.reload();}});
                    } else {
                        layer.msg(res.msg, {time:1500, icon:5, end:function(){location.reload();}});
                    }
                },
                error:function(){
                    layer.msg('ERROR');
                }
            });
        }, function() {

        });
    }
    //设置权限
    function setRule(_filed,_param,_id){
        $.ajax({
            url:'/manage/rule/setRule',
            data:{field:_filed,param:_param,id:_id},
            dataType:'json',
            type:'get',
            async:false,
            success:function(res){
                console.log(res.msg);
                if(res.code==100) {
                    layer.msg(res.msg, {time:1500, icon:6, end:function(){location.reload();}});
                } else {
                    layer.msg(res.msg, {time:1500, icon:5, end:function(){location.reload();}});
                    //window.location.href = "/manage/article/";
                }
            },
            error:function(){
                layer.msg('ERROR');
        }
        });
    }
</script>